jQuery(".txtScroll-top").slide({
	titCell: ".hd ul",
	mainCell: ".bd ul",
	autoPage: true,
	effect: "topLoop", //动画效果
	autoPlay: true, //是否自动轮播
	vis: 3, //显示个数
	delayTime: 1000, //延迟时间
	scroll: 3 //滚动个数
});
var maskBg = $('.mask'),
	yoooClose = $('.close'), // 关闭弹窗
	iKnow = $('.iKnow'); // 抽奖机会用完知道了按钮
var SHAKE_THRESHOLD = 2000; //摇动力度阈值2000，这个测试决定
var shake_time = 0; //摇的次数
var shake_flag = true; //摇的标记，避免重复摇或多摇
var share_time = 0; //分享次数
var last_update = 0; //上一次时间
var x = y = z = last_x = last_y = last_z = 0; //初始化各个轴的加速度以及上一次的加速度
function inits() {
	if(window.DeviceMotionEvent) { //监听运动传感事件
		window.addEventListener('devicemotion', deviceMotionHandler, false);
	} else {
		alert('本设备不支持devicemotion事件');
	}
}
var myAudio=document.getElementById('myAudio');
$(document).on('touchstart',function(){
	myAudio.play();
	myAudio.pause();
})
function deviceMotionHandler(eventData) {
	var acceleration = eventData.accelerationIncludingGravity; //获取含重力的加速度
	var curTime = new Date().getTime(); //当前时间
	if((curTime - last_update) > 100) {
		var diffTime = curTime - last_update;
		last_update = curTime;
		x = acceleration.x;
		y = acceleration.y;
		z = acceleration.z;
		var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
		if(speed > SHAKE_THRESHOLD) { //摇的力度超过阈值触发这里
		  // if(!commonSignIn()) return;
			// if(shake_flag) {
			// 	shake_flag = false;
			// 	myAudio.play();
			// 	// 摇一摇抽奖
			// 	$.ajax({
			// 		url: getIp + '/CARNT/TempActivityWeb/doubleLolitaAct',
			// 		type: "post",
			// 		dataType: "json",
			// 		data: {
			// 			PHONE: _Global_ == 'web' ? getCookie('userName') : phone
			// 		},
			// 		success: function(data) {
			// 			if(data.STATUS_CODE == 1) { // 正常返回
			// 				var dd = new Date(data.EXPDATE);
			// 				$('.promptBox1_1 p:last').html(data.AMOUNT);
			// 				$('.promptBox1_2_1 p').html(data.LOT_NAME);
			// 				$('.promptBox1_2_2 p').html('有效期至：' + formatDate(dd));
			// 				$('.promptBox1_2_3 p').html(data.REMARK);
			// 				setTimeout(function(){
			// 					$('.mask').show();
			// 					$('.promptBoxx').show();
			// 					$('.closeShake').hide();
			// 					shake_flag = true;
			// 				},1500);
			// 			} else if(data.STATUS_CODE == 2) {
			// 				promptBox('分享后可再获得一次抽奖机会！', ' ');
			// 			} else if(data.STATUS_CODE == 3) {
			// 				promptBox('今天抽奖机会已用完！', ' ');
			// 			} else if(data.STATUS_CODE == 15) {
			// 				promptBox('缺少参数！', ' ');
			// 			} else {
			// 				promptBox('服务异常！', ' ');
			// 			}
			// 		}
			// 	});
			// }
			promptBox('活动已结束！', ' ');
		}
		last_x = x;
		last_y = y;
		last_z = z;
	}
}
/*弹窗处理start*/
//关闭弹窗
$('.promptBox4,.promptBox5').click(function(){
		$('.promptBoxx').hide();
		$('.mask').hide();
		shake_flag = true;
		$('.closeShake').hide();
})
$(".close,.mask,.mask2,.closeShake").click(function() {
	$(".mask").hide();
	$(".mask2").hide();
	$(".yyRule").hide();
	shake_flag = true;
	$('.promptBoxx').hide();
	$('.closeShake').hide();
})
//立即使用跳转到我的抽奖记录
$(".promptBox3").click(function(){
	$('.closeShake').hide();
	window.location.href = './award_record.html';
})
//时间戳(毫秒) 转 年-月-日
function   formatDate(now)   {
  var   year=now.getFullYear();
  var   month=now.getMonth()+1;
  var   date=now.getDate();
  return   year+"-"+month+"-"+date;
  }
/* 弹出提示方法 */
function promptBox(text1, text2, func) {
	var promptB = $('.promptBox');
	promptB.find('.firstary').text(text1);
	if(text2) {
		promptB.find('.secondary').text(text2);
	}
	promptB.show();
	$('.mask').show();
	promptB.find('.iKnow').on('click', function() {
		promptB.hide();
		$('.mask').hide();
		func && func();
		shake_flag = true;
	})
}
//规则说明
$('.shakeRuleInfo p').click(function() {
	$(".yyRule").show();
	$(".mask").show();
	$('.closeShake').show();
})
//跳转抽奖记录
function go_award_record() {
	if(!commonSignIn()) return;
	location.href = "./award_record.html";
}
$('.footerAds').on('click',function(){
	if(_Global_==='app'){
		action(20171101);
	}else{
		location.href='./main.html';
	}
})



// ----------------------------------------------------------------- 以下是分享部分
//分享记录
function saveRecord(actId, type) {
var json = {
	'ACT_ID': actId,
	'SHARE_TYPE': type,
	'MOBILE': _Global_ == 'web' ? getCookie('userName') : phone
}
$.ajax({
	type: "post",
	async: false,
	dataType: "json",
	url: getIp + "/CARNT/Act/createShareRecord.action",
	data: json,
	success: function() {}
});
}
// 点击数
var json = {
'actId': 20171102
}

$.ajax({
type: "post",
async: false,
dataType: "json",
url: getIp + "/CARNT/Act/updateActClick.action",
data: json,
success: function(data) {
	//slert("ok");
}
})
var title;
var desc;
var imgUrl;
var linkUrl;
//分享文案
$.ajax({
type: "post",
async: false,
dataType: "json",
url: getIp + "/CARNT/ActWeb/getActivityById.action",
data: {
	ACT_ID: '20171102'
},
success: function(data) {
	title = data.RESULT_DATA[0].SHARE_TITLE;
	desc = data.RESULT_DATA[0].SHARE_CONTENT;
	imgUrl = data.RESULT_DATA[0].SHARE_ICON;
	linkUrl = data.RESULT_DATA[0].LINK_URL;
	document.title = title;
}
});
//获取分享的文案
var timestamp;
var nonceStr;
var signature;
//这个URL是你当前页面的url
var json = {
'url': location.href
}
var u = navigator.userAgent;
var isAndroids = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; // android终端
var isiOSs = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
var urls='';
var appid='';
if(isAndroids){
	urls='../../OAuth/getAccess_token.action';
	appid='wxf71262a112685c25';
}else if(isiOSs){
	urls='../../OAuth/getAccess_tokenIPHONE.action';
	appid='wx054c6f61cacfa911';
}
$.ajax({
type: "post",
async: false,
dataType: "json",
url: urls,
data: json,
success: function(data) {
	timestamp = data.NOW_TIME;
	nonceStr = data.NONCESTR;
	signature = data.SKEY;
	wx.config({
		debug: false, // 开启调试模式,false调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
		appId: appid, // 必填，公众号的唯一标识
		timestamp: timestamp, // 必填，生成签名的时间戳
		nonceStr: nonceStr, // 必填，生成签名的随机串
		signature: signature, // 必填，签名，见附录1
		jsApiList: [
			'onMenuShareTimeline',
			'onMenuShareAppMessage',
			'hideOptionMenu',
			'showOptionMenu'
		]
	});
}
});
wx.ready(function() {

// 分享给朋友
wx.onMenuShareAppMessage({
	title: title,
	desc: desc,
	link: linkUrl,
	imgUrl: imgUrl,
	trigger: function(res) {},
	success: function(res) {
		saveRecord(20171102, 1);
	},
	cancel: function(res) {},
	fail: function(res) {
		alert(JSON.stringify(res));
	}
});

//分享朋友圈
wx.onMenuShareTimeline({
	title: title,
	desc: desc,
	link: linkUrl,
	imgUrl: imgUrl,
	trigger: function(res) {

	},
	success: function(res) {
		saveRecord(20171102, 1);
	},
	cancel: function(res) {},
	fail: function(res) {
		alert(JSON.stringify(res));
	}
});
});
